package com.cx.common.log.config;

import com.cx.common.log.interceptor.ThreadPoolExecutorMdcWrapper;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.concurrent.LinkedBlockingDeque;
import java.util.concurrent.TimeUnit;

@Configuration
public class ThreadConfig {
    public static final int CPU_COUNT = Runtime.getRuntime().availableProcessors();
    public static final int MAX_POOL_SIZE = CPU_COUNT * 2 + 1;

    @Bean
    public ThreadPoolExecutorMdcWrapper getThreadPoolExecutorMdcWrapper() {
        return new ThreadPoolExecutorMdcWrapper(CPU_COUNT,
                MAX_POOL_SIZE,
                5,
                TimeUnit.SECONDS,
                new LinkedBlockingDeque<>(5)
        );
    }
}
